<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>

<div style="margin-top: 10px;">
	<div class="hot-container has-scroll">
		<div id="hot_my"></div>
	</div>
</div>
<script type="text/javascript">
	var $hot = null;

	function createSpreadsheetData(rowCount, colCount) {
		rowCount = typeof rowCount === 'number' ? rowCount : 100;
		colCount = typeof colCount === 'number' ? colCount : 4;
		var rows = [], i, j;
		for (i = 0; i < rowCount; i++) {
			var row = [];
			for (j = 0; j < colCount; j++) {
				row.push('');
			}
			rows.push(row);
		}
		return rows;
	}

	function init() {
		var hot_my = document.getElementById('hot_my');

		// Initialize with options
		$hot = new Handsontable(hot_my, {
			startRows : 10,
			startCols : 6,
			manualColumnResize : true,
			manualRowResize : true,
			manualColumnMove : true,
			manualRowMove : true,
			columnSorting : true,
			rowHeaders : true,
			colHeaders : true,
			contextMenu : true,
			autoColumnSize : true,
			stretchH : 'all',
			mergeCells : true,
			manualColumnFreeze : true
		});

		/*  $hot.updateSettings({
			contextMenu : {
				items : {
					"row_above" : {name : '在上面添加行'},
					"row_below" : {name : '在下面添加行'},
					"remove_row" : {name : '删除当前行'}
				}
			}
		}); */
	}

/* 	function loadTable() {
		var id = "181b061f-9f39-47fa-94a0-e2e5af92ee";
		c.log(id+"777");
		var json = null;
		var url = $.getVirtualPath()+"/admin/experimentExcel/data/dictColumnJson?id=" + id;
		json = $.getJsonPost(url);
		c.log(json);
		if ($.isNull(json)) {
			alert("2323");
			return getEmptyData();
		}
		return json;
	} */

	function getEmptyData() {
		var hot_borders_data = createSpreadsheetData(10, 6);
		return hot_borders_data;
	}

	function reload() {
		var data = $("#markValue").val();
		c.log(data);
		if (data!="" && data !=null) {
			var dataArray = JSON.parse(data);
			c.log(dataArray);
			$hot.loadData(dataArray);
			$hot.render();
		 } else {
			data = getEmptyData();
			$hot.loadData(data);
			$hot.render();
		} 
	}

	function saveForm() {
		var id = $.getUrlParam("id");
		c.log(id+"787878");
		deleteEmpty();
		var datas = $hot.getData();
		c.log(datas);
		if(id==null)
			var url = $.getVirtualPath() + "/admin/experimentExcel/data/saveValue";
		else
			var url = $.getVirtualPath() + "/admin/experimentExcel/data/saveValue?id="+id;
		c.log(url);
		$.ajax({
			url : url,
			type : 'post',
			contentType : "application/json",
			data : JSON.stringify(datas),
			success:function(result){
				$.topNotify(result.message,result.resultType);	
				closeModal();
			
			}
		});
	}

	//删除空行
	function deleteEmpty() {
		var rows = $hot.countRows();
		for (var i = rows - 1; i >= 0; i--) {
			if ($hot.isEmptyRow(i)) {
				$hot.alter('remove_row', i);
			}
		}
	}
	</script>
<%@ include
	file="/WEB-INF/views/shared/base/scripts/limitless/default/handsontable.jsp"%>
	
<%@ include
	file="/WEB-INF/views/shared/base/scripts/limitless/default/ui/prism.jsp"%>
	
